﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChessGameV2.Pieces;

namespace ChessGameV2.AI
{
    public class Evalution
    {
        public Evalution()
        {
     
        }
        /// <summary>
        /// Ham tinh gia tri quan xe
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        private float Rook(int pos, int _player)
        {
            if(_player == 1)
                return EvalTable.rook + MaterialTable.rook[pos];
            else 
                return EvalTable.rook + MaterialTable.rook[119 - pos];
        }
        /// <summary>
        /// Ham tinh gia tri quan Hau
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        private float Queen(int pos, int _player)
        {
            if (_player == 1)
                return EvalTable.queen + MaterialTable.queen[pos];
            else
                return EvalTable.queen + MaterialTable.queen[119 - pos];
        }
        /// <summary>
        /// Ham tinh gia tri quan tot
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        private float Pawn(int pos, int _player)
        {
            if (_player == 1)
                return EvalTable.pawn + MaterialTable.pawn[pos];
            else
                return EvalTable.pawn + MaterialTable.pawn[119 - pos];
        }
        /// <summary>
        /// Ham tinh gia tri Vua
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        private float King(int pos, int _player)
        {
            if (_player == 1)
                return EvalTable.king + MaterialTable.king[pos];
            else
                return EvalTable.king + MaterialTable.king[119 - pos];
        }
        /// <summary>
        /// Ham tinh gia tri quan tuong
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        private float Bishop(int pos, int _player)
        {
            if (_player == 1)
                return EvalTable.bishop + MaterialTable.bishop[pos];
            else
                return EvalTable.bishop + MaterialTable.bishop[119 - pos];
        }
        /// <summary>
        /// Ham tinh gia tri quan ma
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        private float Knight(int pos, int _player)
        {
            if (_player == 1)
                return EvalTable.knight + MaterialTable.knight[pos];
            else
                return EvalTable.knight + MaterialTable.knight[119 - pos];
        }
        /// <summary>
        /// Ham tinh gia tri toan ban do
        /// </summary>
        /// <param name="board"></param>
        /// <param name="_player"></param>
        /// <returns></returns>
        public float Board(int[] board, int _player)
        {
            float total = 0.0f;
            float figur = 0.0f;
            for (int i = 21; i < 99; i++)
            {
                 if (board[i] != 0 && board[i] != 99)
                {
                    int _p = board[i] % 100 /10;
                    switch (board[i] % 10)
                    {
                        case 1:
                            figur = Pawn(i,_p); break;
                        case 2:
                            figur = Knight(i,_p); break;
                        case 3:
                            figur = Bishop(i,_p); break;
                        case 4:
                            figur = Rook(i,_p); break;
                        case 5:
                            figur = Queen(i,_p); break;
                        case 6:
                            figur = King(i,_p); break;
                    }

                    if (board[i] % 100 / 10 == _player)
                        total += figur;
                    else
                        total -= figur;
                }
            }
            return total;// +moveCount(board) + centerPos(board);
        }
        /*
        private int moveCount(int[] board, int pmax, int pmin)
        {
            int P1Count = movecontrol.getListMove(this.pmax, board).Count;
            int P2Count = movecontrol.getListMove(this.pmin, board).Count;

            if (P1Count == P2Count)
                return 0;
            if (P1Count > P2Count)
                return EvalTable.moveCount;
            else 
                return -EvalTable.moveCount;
        }
        private int findcenterPos(int pos,)
        {
            if (pos == 0) return 0;
            if (pos % 100 / 10 == this.pmax)
                return 1;
            else return -1;
        }
        public int centerPos(int[] board)
        {
            return findcenterPos(board[54]) + findcenterPos(board[55]) + findcenterPos(board[64]) + findcenterPos(board[65]);
        }
        */
    }
}
